import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

class SmartDialogDemo extends StatefulWidget {
  SmartDialogDemo({Key? key}) : super(key: key);

  @override
  _SmartDialogDemoState createState() => _SmartDialogDemoState();
}

class _SmartDialogDemoState extends State<SmartDialogDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('smartDialog demo'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () {
                SmartDialog.compatible
                    .showToast('test toast', time: Duration(seconds: 2));
              },
              child: Text('show toast '),
            ),
            ElevatedButton(
              onPressed: () async {
                // SmartDialog.showLoading();
                // await Future.delayed(Duration(seconds: 2));
                // SmartDialog.dismiss();
                // SmartDialog.show(widget:Text('hello'));
              },
              child: Text('show loading '),
            ),
            ElevatedButton(
              onPressed: () {
                SmartDialog.compatible.show(
                  animationDurationTemp: Duration(milliseconds: 200),
                  //默认:false；是否穿透遮罩背景,交互遮罩之后控件，true：点击能穿透背景，
                  //false：不能穿透；穿透遮罩设置为true，背景遮罩会自动变成透明（必须）
                  isPenetrateTemp: false,
                  // 默认：true；点击遮罩，是否关闭dialog---true：点击遮罩关闭dialog，false：不关闭
                  clickBgDismissTemp: true,
                  maskColorTemp: Colors.black.withOpacity(0.5),
                  // maskWidgetTemp: Container(
                  //   height: MediaQuery.of(context).size.height - 200,
                  //   // color: Colors.black.withOpacity(0.01),
                  //   decoration: BoxDecoration(
                  //       gradient: LinearGradient(
                  //     colors: [Colors.red, Colors.blue],
                  //     begin: Alignment.topCenter,
                  //     end: Alignment.bottomCenter,
                  //   )),
                  // ),

                  widget: Container(
                      height: 300,
                      child: SingleChildScrollView(
                        child: Column(
                          children: [
                            Container(
                              alignment: Alignment.center,
                              width: MediaQuery.of(context).size.width,
                              color: Colors.red,
                              height: 200,
                              child: Text(
                                'hello',
                                style: TextStyle(fontSize: 30),
                              ),
                            ),
                            Container(
                              alignment: Alignment.center,
                              width: MediaQuery.of(context).size.width,
                              color: Colors.blue,
                              height: 200,
                              child: Text(
                                'hello',
                                style: TextStyle(fontSize: 30),
                              ),
                            ),
                            Container(
                              alignment: Alignment.center,
                              width: MediaQuery.of(context).size.width,
                              color: Colors.yellow,
                              height: 200,
                              child: Text(
                                'hello',
                                style: TextStyle(fontSize: 30),
                              ),
                            )
                          ],
                        ),
                      )),
                  alignmentTemp: Alignment.bottomCenter, //更alignment即可改变弹出动画位置
                );
              },
              child: Text('show'),
            ),
          ],
        ),
      ),
    );
  }
}
